//
//  LGDiscoverSearchView.swift
//  01-Weibo项目练习-1
//
//  Created by 李李刚 on 16/3/3.
//  Copyright © 2016年 李李刚. All rights reserved.
//

import UIKit

class LGDiscoverSearchView: UIView {

  
    
    
    @IBOutlet weak var seachTextRight: NSLayoutConstraint!
    
    @IBOutlet weak var seachText: UITextField!
    
    
    @IBOutlet weak var cancelButton: UIButton!
    
    
    @IBAction func textEditingDidBegin(sender: UITextField) {
        
        //当点击输入框时显示取消按钮
//        self.seachText.frame.size.width = UIScreen.mainScreen().bounds.size.width - cancelButton.bounds.size.width
        
        self.seachTextRight.constant = self.cancelButton.bounds.size.width
        
        
        
        //动画效果
        UIView.animateWithDuration(0.5) { () -> Void in
            //闭包中调用其他属性需要使用self
            self.seachText.layoutIfNeeded()
            
        }
        
        
    }
    
    
    @IBAction func cancelDidClick(sender: UIButton) {
        
        print("取消按钮点击")
        //取消按钮点击
        self.seachText.resignFirstResponder()
        
        self.seachTextRight.constant = 0
        
        UIView.animateWithDuration(0.5) { () -> Void in
            
            self.seachText.layoutIfNeeded()
            
        }
        
    }
    
    //搜索栏的搜索图片--leftView
    private var leftView:UIImageView = {
        let leView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
       
        leView.contentMode = .Center
        
        return leView
        
    }()
    
    override func awakeFromNib() {
        
        self.seachText.leftView = self.leftView
        
        seachText.leftViewMode = .Always
        
        leftView.frame.size = CGSizeMake(self.frame.height , self.frame.height)
        
        
    }
    
    

}
